
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

using Swaf;
using Swaf.Container;

namespace eCom.Gui.AspNet
{
	[ParseChildren(false)]
	public class StandAloneProductListDisplay : Swaf.Gui.AspNet2.UserControl
	{
		protected List<Control> m_innerChildren = null;
		protected FlexiMap m_macros = new FlexiMap();

		[Category("Appearance")]
		public string PID { get { return (string)m_macros.get("pid"); } set { m_macros.put("pid", value); } }

		[Category("Appearance")]
		public string ParentBizProc { get { return (string)m_macros.get("parentBizProc"); } set { m_macros.put("parentBizProc", value); } }

		[Category("Appearance")]
		public string BoxSkinId { get { return (string)m_macros.get("skinId"); } set { m_macros.put("skinId", value); } }

		[Category("Appearance")]
		public string InnerNumLayers { get { return (string)m_macros.get("innerNumLayers"); } set { m_macros.put("innerNumLayers", value); } }

		[Category("Appearance")]
		public string InnerBoxClass { get { return (string)m_macros.get("innerBoxClass"); } set { m_macros.put("innerBoxClass", value); } }

		[Category("Appearance")]
		public string ListTemplate { get { return (string)m_macros.get("listType"); } set { m_macros.put("listType", value); } }

		[Category("Appearance")]
		public string NavLink { get { return (string)m_macros.get("navLink2"); } set { m_macros.put("navLink2", value); } }

		[Category("Appearance")]
		public string ImageRes { get { return (string)m_macros.get("imageRes"); } set { m_macros.put("imageRes", value); } }

		[Category("Appearance")]
		public string MaxElements { get { return (string)m_macros.get("maxElements"); } set { m_macros.put("maxElements", value); } }

		[Category("Appearance")]
		public string ColumnElements { get { return (string)m_macros.get("colElements"); } set { m_macros.put("colElements", value); } }

		[Category("Appearance")]
		public string IncludeSelf { get { return (string)m_macros.get("includeSelf"); } set { m_macros.put("includeSelf", value); } }

		[Category("Appearance")]
		public string EntireTree { get { return (string)m_macros.get("entireTree"); } set { m_macros.put("entireTree", value); } }

		[Category("Appearance")]
		public string DetailLevel { get { return (string)m_macros.get("detailLevel"); } set { m_macros.put("detailLevel", value); } }

		[Category("Appearance")]
		public string AddFirstButtonText { get { return (string)m_macros.get("addFirstTxt"); } set { m_macros.put("addFirstTxt", value); } }

		[Category("Appearance")]
		public string UpdateButtonText { get { return (string)m_macros.get("updateTxt"); } set { m_macros.put("updateTxt", value); } }

		[Category("Appearance")]
		public string PriceFormat { get { return (string)m_macros.get("priceFormat"); } set { m_macros.put("priceFormat", value); } }

		protected override string createCacheKey()
		{
			string key = base.createCacheKey() + WidgetId;
			s_content[key] = null;
			return key;
		}

		protected override System.IO.TextReader Html
		{
			get
			{
				if (NavLink == null)
					NavLink = "$CmpSetting(sitePath)$/products/$CalcArticleIds($pid$,$uniqueId$)$.aspx";
				if (ParentBizProc == null)
					ParentBizProc = "orderBP";
				if (MaxElements == null)
					MaxElements = "-1";
				if (ImageRes == null)
					ImageRes = "Thumbnail";
				if (ColumnElements == null)
					ColumnElements = "1";
				if (IncludeSelf == null)
					IncludeSelf = "True";
				if (EntireTree == null)
					EntireTree = "True";
				if (DetailLevel == null)
					DetailLevel = "basicDetails";
				if (AddFirstButtonText == null)
					AddFirstButtonText = "Add To Cart";
				if (UpdateButtonText == null)
					UpdateButtonText = "Update Quantity";
				if (PriceFormat == null)
					PriceFormat = "_CmpCur";

				m_macros.put("id", ID);
				string html = base.Html.ReadToEnd();
				html = Swaf.Application.currentApp.resMgr.resolve(html, m_macros);
				html = html.Replace("$navLink$", ((string)m_macros.get("navLink2")));//.Replace("&","&amp;"));
				return new System.IO.StringReader(html);
			}

		}

		protected override bool createControls()
		{
			if (m_innerChildren == null && Controls.Count > 0)
			{
				m_innerChildren = new List<Control>();
				foreach (Control c in Controls)
					m_innerChildren.Add(c);
			}
			return base.createControls();
		}
		protected override void RenderContents(HtmlTextWriter output)
		{
			if (m_innerChildren != null)
			{
				Panel mainArea = searchControl("MainArea", this) as Panel;
				if (mainArea != null)
					foreach (Control c in m_innerChildren)
						mainArea.Controls.Add(c);
			}
			base.RenderContents(output);
		}

	}
}
